diff --git a/src/main/java/com/lq/cms/dao/AdminBaseDao.java b/src/main/java/com/lq/cms/dao/AdminBaseDao.java index 4cf7b18..1a2ea7d 100755 --- a/src/main/java/com/lq/cms/dao/AdminBaseDao.java +++ b/src/main/java/com/lq/cms/dao/AdminBaseDao.java @@ -5,7 +5,7 @@ import com.lq.code.dao.BaseDao; import java.util.List; -public interface AdminBaseDao extends BaseDao { +public interface AdminBaseDao extends BaseDao { List findListPage(V vo); diff --git a/src/main/java/com/lq/cms/service/impl/WechatRuleServiceImpl.java b/src/main/java/com/lq/cms/service/impl/WechatRuleServiceImpl.java index 5927ffe..f19004e 100644 --- a/src/main/java/com/lq/cms/service/impl/WechatRuleServiceImpl.java +++ b/src/main/java/com/lq/cms/service/impl/WechatRuleServiceImpl.java @@ -2,6 +2,7 @@ package com.lq.cms.service.impl; import com.lq.cms.emun.StatusTypeEnum; import com.lq.cms.emun.WechatKeywordMatchinTypeEnum; +import com.lq.cms.emun.WechatRuleReplyTypeEnum; import com.lq.cms.service.WechatRuleService; import com.lq.cms.vo.WechatRuleVo; import com.lq.code.dao.BaseDao; @@ -22,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; /** * @Author: qi @@ -37,20 +39,58 @@ public class WechatRuleServiceImpl extends BaseServiceImpl implement private WechatKeywordDao wechatKeywordDao; @Autowired private WechatRuleMessageDao wechatRuleMessageDao; + @Autowired + private WechatMessageDao wechatMessageDao; @Override public BaseMessage getByKeyworkdAndWechatInfoId(String keyworkd, WechatInfo wechatInfo) { + + List wechatMessageList = new ArrayList<>(); + //公众号相关回复规则 List wechatRuleList = wechatRuleDao.findByWechatInfoIdAndStatus(wechatInfo.getId(),StatusTypeEnum.STATUS_ACTIVITY_YES.getValue()); wechatRuleList.forEach((wechatRule)->{ + //规则相关关键词 List wechatKeywordList = wechatKeywordDao.findByWechatRuleIdAndStatus(wechatRule.getId(),StatusTypeEnum.STATUS_ACTIVITY_YES.getValue()); wechatKeywordList.forEach((wechatKeyword)->{ if (WechatKeywordMatchinTypeEnum.KEYWORD_ALL.getValue().equals(wechatKeyword.getMatchinType())){ if (keyworkd.equals(wechatKeyword.getKeyword())){ - List wechatMessageList = null; + List wechatRuleMessageList = wechatRuleMessageDao.findByWechatRuleId(wechatRule.getId()); + if (WechatRuleReplyTypeEnum.REPLY_ALL.getValue().equals(wechatRule.getReplyType())) { + wechatRuleMessageList.forEach((wechatRuleMessage) -> { + WechatMessage wechatMessage = wechatMessageDao.findOne(wechatRuleMessage.getId()); + if (wechatMessage != null) { + wechatMessageList.add(wechatMessage); + } + }); + } + if (WechatRuleReplyTypeEnum.REPLY_RANDOM.getValue().equals(wechatRule.getReplyType())){ + ThreadLocalRandom threadLocalRandom=ThreadLocalRandom.current(); + int index = ThreadLocalRandom.current().nextInt(wechatRuleMessageList.size()); + WechatRuleMessage wechatRuleMessage = wechatRuleMessageList.get(index); + WechatMessage wechatMessage = wechatMessageDao.findOne(wechatRuleMessage.getId()); + wechatMessageList.add(wechatMessage); + } } }else { - + if (keyworkd.indexOf(wechatKeyword.getKeyword())!=-1){ + List wechatRuleMessageList = wechatRuleMessageDao.findByWechatRuleId(wechatRule.getId()); + if (WechatRuleReplyTypeEnum.REPLY_ALL.getValue().equals(wechatRule.getReplyType())) { + wechatRuleMessageList.forEach((wechatRuleMessage) -> { + WechatMessage wechatMessage = wechatMessageDao.findOne(wechatRuleMessage.getId()); + if (wechatMessage != null) { + wechatMessageList.add(wechatMessage); + } + }); + } + if (WechatRuleReplyTypeEnum.REPLY_RANDOM.getValue().equals(wechatRule.getReplyType())){ + ThreadLocalRandom threadLocalRandom=ThreadLocalRandom.current(); + int index = ThreadLocalRandom.current().nextInt(wechatRuleMessageList.size()); + WechatRuleMessage wechatRuleMessage = wechatRuleMessageList.get(index); + WechatMessage wechatMessage = wechatMessageDao.findOne(wechatRuleMessage.getId()); + wechatMessageList.add(wechatMessage); + } + } } }); diff --git a/src/main/java/com/lq/dao/WechatRuleMessageDao.java b/src/main/java/com/lq/dao/WechatRuleMessageDao.java index 57e3434..48b85e4 100644 --- a/src/main/java/com/lq/dao/WechatRuleMessageDao.java +++ b/src/main/java/com/lq/dao/WechatRuleMessageDao.java @@ -1,6 +1,7 @@ package com.lq.dao; import com.lq.code.dao.BaseDao; +import com.lq.entity.WechatMessage; import com.lq.entity.WechatRuleMessage; import org.apache.ibatis.annotations.Param; @@ -11,4 +12,5 @@ public interface WechatRuleMessageDao extends BaseDao { WechatRuleMessage getByRuleIdAndMessageId(@Param("ruleId")Long ruleId,@Param("messageId")Long messageId); List findByWechatRuleId(@Param("wechatRuleId")Long wechatRuleId); + } diff --git a/src/main/java/com/lq/entity/SysPermission.java b/src/main/java/com/lq/entity/SysPermission.java index 9601414..5b07b1a 100755 --- a/src/main/java/com/lq/entity/SysPermission.java +++ b/src/main/java/com/lq/entity/SysPermission.java @@ -7,6 +7,10 @@ import com.lq.code.entity.IdEntity; */ public class SysPermission extends IdEntity{ + /** + * 关联资源ID + */ + private Long sysResourceId; /** * 权限名称 */ @@ -15,11 +19,18 @@ public class SysPermission extends IdEntity{ * 权限类型 */ private Integer permissionType; - /**· + /** * 权限键值 */ private String permissionKey; + public Long getSysResourceId() { + return sysResourceId; + } + + public void setSysResourceId(Long sysResourceId) { + this.sysResourceId = sysResourceId; + } public String getName() { return name;