新增微信公众号消息功能

master
星期八 6 years ago
parent 7c0373da25
commit 757c3bc66d
  1. 4
      src/main/java/com/lq/cms/service/WechatMessageService.java
  2. 4
      src/main/java/com/lq/cms/service/WechatRuleService.java
  3. 16
      src/main/java/com/lq/cms/service/impl/WechatMessageServiceImpl.java
  4. 23
      src/main/java/com/lq/cms/service/impl/WechatRuleServiceImpl.java
  5. 12
      src/main/java/com/lq/cms/web/wechat/WechatMessageController.java
  6. 12
      src/main/java/com/lq/cms/web/wechat/WechatRuleController.java
  7. 6
      src/main/webapp/WEB-INF/views/jsp/cms/wechat/rule/index.jsp

@ -3,8 +3,10 @@ package com.lq.cms.service;
import com.lq.cms.vo.WechatMessageVo; import com.lq.cms.vo.WechatMessageVo;
import com.lq.entity.WechatMessage; import com.lq.entity.WechatMessage;
import java.util.List;
public interface WechatMessageService extends AdminBaseService<WechatMessage,WechatMessageVo> {
public interface WechatMessageService extends AdminBaseService<WechatMessage,WechatMessageVo> {
List<WechatMessageVo> findAllWechatMessageVo();
} }

@ -27,6 +27,10 @@ public interface WechatRuleService extends BaseService<WechatRule> {
* 保存规则和规则对应的关键字 * 保存规则和规则对应的关键字
*/ */
WechatRule saveRuleAndkeyword(WechatRule wechatRule, List<WechatKeyword> wechatKeywordList); WechatRule saveRuleAndkeyword(WechatRule wechatRule, List<WechatKeyword> wechatKeywordList);
/**
* 保存规则和规则对应的关键字
*/
WechatRule saveRule(WechatRuleVo wechatRuleVo);
/** /**
* 通过微信公众号详情ID查找关联规则 * 通过微信公众号详情ID查找关联规则

@ -3,11 +3,15 @@ package com.lq.cms.service.impl;
import com.lq.cms.dao.AdminBaseDao; import com.lq.cms.dao.AdminBaseDao;
import com.lq.cms.service.WechatMessageService; import com.lq.cms.service.WechatMessageService;
import com.lq.cms.vo.WechatMessageVo; import com.lq.cms.vo.WechatMessageVo;
import com.lq.code.util.BeanUtil;
import com.lq.dao.WechatMessageDao; import com.lq.dao.WechatMessageDao;
import com.lq.entity.WechatMessage; import com.lq.entity.WechatMessage;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service @Service
public class WechatMessageServiceImpl extends AdminBaseServiceImpl<WechatMessage,WechatMessageVo> implements WechatMessageService { public class WechatMessageServiceImpl extends AdminBaseServiceImpl<WechatMessage,WechatMessageVo> implements WechatMessageService {
@ -21,4 +25,16 @@ public class WechatMessageServiceImpl extends AdminBaseServiceImpl<WechatMessage
return wechatMessageDao; return wechatMessageDao;
} }
@Override
public List<WechatMessageVo> findAllWechatMessageVo() {
List<WechatMessageVo> wechatMessageVoList = new ArrayList<>();
List<WechatMessage> wechatMessageList = wechatMessageDao.findAll();
wechatMessageList.forEach(wechatMessage -> {
WechatMessageVo wechatMessageVo = new WechatMessageVo();
BeanUtil.copyNotNull(wechatMessageVo,wechatMessage);
wechatMessageVoList.add(wechatMessageVo);
});
return wechatMessageVoList;
}
} }

@ -51,6 +51,7 @@ public class WechatRuleServiceImpl extends BaseServiceImpl<WechatRule> implement
SysUser loginUser=(SysUser) subject.getPrincipal(); SysUser loginUser=(SysUser) subject.getPrincipal();
wechatRule.setCreateUserId(loginUser.getId()); wechatRule.setCreateUserId(loginUser.getId());
wechatRule.setStatus(StatusTypeEnum.STATUS_ACTIVITY_YES.getValue()); wechatRule.setStatus(StatusTypeEnum.STATUS_ACTIVITY_YES.getValue());
wechatRule.setCreateTime(new Date());
wechatRuleDao.save(wechatRule); wechatRuleDao.save(wechatRule);
wechatKeywordList.forEach(wechatKeyword -> { wechatKeywordList.forEach(wechatKeyword -> {
wechatKeyword.setCreateTime(new Date()); wechatKeyword.setCreateTime(new Date());
@ -58,10 +59,32 @@ public class WechatRuleServiceImpl extends BaseServiceImpl<WechatRule> implement
wechatKeyword.setStatus(StatusTypeEnum.STATUS_ACTIVITY_YES.getValue()); wechatKeyword.setStatus(StatusTypeEnum.STATUS_ACTIVITY_YES.getValue());
wechatKeywordDao.save(wechatKeyword); wechatKeywordDao.save(wechatKeyword);
}); });
return wechatRule;
}
@Transactional(rollbackFor = Exception.class)
@Override
public WechatRule saveRule(WechatRuleVo wechatRuleVo) {
Subject subject= SecurityUtils.getSubject();
SysUser loginUser=(SysUser) subject.getPrincipal();
WechatRule wechatRule = new WechatRule();
BeanUtil.copyNotNull(wechatRule,wechatRuleVo);
wechatRule.setCreateUserId(loginUser.getId());
wechatRule.setStatus(StatusTypeEnum.STATUS_ACTIVITY_YES.getValue());
wechatRule.setCreateTime(new Date()); wechatRule.setCreateTime(new Date());
wechatRuleDao.save(wechatRule);
List<WechatKeyword> wechatKeywordList = wechatRuleVo.getWechatKeywordList();
wechatKeywordList.forEach(wechatKeyword -> {
wechatKeyword.setCreateTime(new Date());
wechatKeyword.setWechatRuleId(wechatRule.getId());
wechatKeyword.setStatus(StatusTypeEnum.STATUS_ACTIVITY_YES.getValue());
wechatKeywordDao.save(wechatKeyword);
});
return wechatRule; return wechatRule;
} }
@Override @Override
public List<WechatRuleVo> findByWechatInfoId(Long wechatInfoId) { public List<WechatRuleVo> findByWechatInfoId(Long wechatInfoId) {
List<WechatRuleVo> wechatRuleVos = new ArrayList<>(); List<WechatRuleVo> wechatRuleVos = new ArrayList<>();

@ -5,12 +5,15 @@ import com.lq.cms.service.AdminBaseService;
import com.lq.cms.service.WechatMessageService; import com.lq.cms.service.WechatMessageService;
import com.lq.cms.vo.WechatMessageVo; import com.lq.cms.vo.WechatMessageVo;
import com.lq.cms.web.AdminBaseController; import com.lq.cms.web.AdminBaseController;
import com.lq.code.entity.AjaxResult;
import com.lq.entity.WechatMessage; import com.lq.entity.WechatMessage;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -40,7 +43,14 @@ public class WechatMessageController extends AdminBaseController<WechatMessage,W
return "cms/wechat/message/edit"; return "cms/wechat/message/edit";
} }
@RequestMapping("/findMessageDataList")
@ResponseBody
public Object findAll(){
List<WechatMessageVo> wechatMessageVoList = wechatMessageService.findAllWechatMessageVo();
AjaxResult ajaxResult = new AjaxResult();
ajaxResult.setData(wechatMessageVoList);
return ajaxResult;
}
@Override @Override
public AdminBaseService getBaseService() { public AdminBaseService getBaseService() {

@ -7,10 +7,9 @@ import com.lq.cms.service.WechatInfoService;
import com.lq.cms.service.WechatRuleService; import com.lq.cms.service.WechatRuleService;
import com.lq.cms.vo.WechatRuleVo; import com.lq.cms.vo.WechatRuleVo;
import com.lq.code.entity.AjaxResult; import com.lq.code.entity.AjaxResult;
import com.lq.code.util.BeanUtil; import com.lq.code.util.StringUtil;
import com.lq.entity.WechatInfo; import com.lq.entity.WechatInfo;
import com.lq.entity.WechatKeyword; import com.lq.entity.WechatKeyword;
import com.lq.entity.WechatRule;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -62,10 +61,11 @@ public class WechatRuleController {
@RequestMapping("/save") @RequestMapping("/save")
public Object save(WechatRuleVo vo,String keywordListStr,String messageListStr,Long wechatInfoId){ public Object save(WechatRuleVo vo,String keywordListStr,String messageListStr,Long wechatInfoId){
AjaxResult ajaxResult = new AjaxResult(); AjaxResult ajaxResult = new AjaxResult();
WechatRule wechatRule = new WechatRule(); if (StringUtil.isNotNull(keywordListStr)) {
List<WechatKeyword> wechatKeywordList = JSON.parseArray(keywordListStr,WechatKeyword.class); List<WechatKeyword> wechatKeywordList = JSON.parseArray(keywordListStr, WechatKeyword.class);
BeanUtil.copyNotNull(wechatRule,vo); vo.setWechatKeywordList(wechatKeywordList);
wechatRuleService.saveRuleAndkeyword(wechatRule,wechatKeywordList); }
wechatRuleService.saveRule(vo);
return ajaxResult; return ajaxResult;
} }

@ -265,7 +265,6 @@
return ; return ;
} }
wechatKeyWord.keyword = keywordContent; wechatKeyWord.keyword = keywordContent;
wechatKeyWord.matchinType = matchinType; wechatKeyWord.matchinType = matchinType;
keywordObjeList.push(wechatKeyWord); keywordObjeList.push(wechatKeyWord);
}); });
@ -277,7 +276,6 @@
var messageList = new Array(); var messageList = new Array();
messageSet.forEach(function (element, sameElement, set) { messageSet.forEach(function (element, sameElement, set) {
messageList.push(element); messageList.push(element);
// messageList.push(e);
}); });
messageSet.clear(); messageSet.clear();
@ -393,7 +391,7 @@
data.messageType = 'text-image'; data.messageType = 'text-image';
$.ajax({ $.ajax({
type:"post", type:"post",
url:"${ctx}/admin/wechat/getMessageDataList.htm", url:"${ctx}/cms/wechat/message/findMessageDataList",
traditional:true, traditional:true,
data:data, data:data,
async:false, async:false,
@ -637,7 +635,7 @@
function appendAlertHtml(data){ function appendAlertHtml(data){
var isShow ; var isShow ;
var wechatMessageList = data.wechatMessagList; var wechatMessageList = data;
var html = '<div class="alert"><div class="left-navigation"><p>图文('+data.wechatMessageCount+')</p></div>'; var html = '<div class="alert"><div class="left-navigation"><p>图文('+data.wechatMessageCount+')</p></div>';
html += ' <div class="alert-content">'; html += ' <div class="alert-content">';
for(var i = 0 ;i < wechatMessageList.length;i++){ for(var i = 0 ;i < wechatMessageList.length;i++){

Loading…
Cancel
Save