diff --git a/src/main/java/com/lq/cms/service/WechatMessageService.java b/src/main/java/com/lq/cms/service/WechatMessageService.java index bf000fe..9bb4adb 100755 --- a/src/main/java/com/lq/cms/service/WechatMessageService.java +++ b/src/main/java/com/lq/cms/service/WechatMessageService.java @@ -3,8 +3,10 @@ package com.lq.cms.service; import com.lq.cms.vo.WechatMessageVo; import com.lq.entity.WechatMessage; +import java.util.List; -public interface WechatMessageService extends AdminBaseService { +public interface WechatMessageService extends AdminBaseService { + List findAllWechatMessageVo(); } diff --git a/src/main/java/com/lq/cms/service/WechatRuleService.java b/src/main/java/com/lq/cms/service/WechatRuleService.java index b9fe082..99b0987 100644 --- a/src/main/java/com/lq/cms/service/WechatRuleService.java +++ b/src/main/java/com/lq/cms/service/WechatRuleService.java @@ -27,6 +27,10 @@ public interface WechatRuleService extends BaseService { * 保存规则和规则对应的关键字 */ WechatRule saveRuleAndkeyword(WechatRule wechatRule, List wechatKeywordList); + /** + * 保存规则和规则对应的关键字 + */ + WechatRule saveRule(WechatRuleVo wechatRuleVo); /** * 通过微信公众号详情ID查找关联规则 diff --git a/src/main/java/com/lq/cms/service/impl/WechatMessageServiceImpl.java b/src/main/java/com/lq/cms/service/impl/WechatMessageServiceImpl.java index 2f77616..e701a8b 100755 --- a/src/main/java/com/lq/cms/service/impl/WechatMessageServiceImpl.java +++ b/src/main/java/com/lq/cms/service/impl/WechatMessageServiceImpl.java @@ -3,11 +3,15 @@ package com.lq.cms.service.impl; import com.lq.cms.dao.AdminBaseDao; import com.lq.cms.service.WechatMessageService; import com.lq.cms.vo.WechatMessageVo; +import com.lq.code.util.BeanUtil; import com.lq.dao.WechatMessageDao; import com.lq.entity.WechatMessage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + @Service public class WechatMessageServiceImpl extends AdminBaseServiceImpl implements WechatMessageService { @@ -21,4 +25,16 @@ public class WechatMessageServiceImpl extends AdminBaseServiceImpl findAllWechatMessageVo() { + List wechatMessageVoList = new ArrayList<>(); + List wechatMessageList = wechatMessageDao.findAll(); + wechatMessageList.forEach(wechatMessage -> { + WechatMessageVo wechatMessageVo = new WechatMessageVo(); + BeanUtil.copyNotNull(wechatMessageVo,wechatMessage); + wechatMessageVoList.add(wechatMessageVo); + }); + + return wechatMessageVoList; + } } 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 5aa8d6d..b6f7604 100644 --- a/src/main/java/com/lq/cms/service/impl/WechatRuleServiceImpl.java +++ b/src/main/java/com/lq/cms/service/impl/WechatRuleServiceImpl.java @@ -51,6 +51,7 @@ public class WechatRuleServiceImpl extends BaseServiceImpl implement SysUser loginUser=(SysUser) subject.getPrincipal(); wechatRule.setCreateUserId(loginUser.getId()); wechatRule.setStatus(StatusTypeEnum.STATUS_ACTIVITY_YES.getValue()); + wechatRule.setCreateTime(new Date()); wechatRuleDao.save(wechatRule); wechatKeywordList.forEach(wechatKeyword -> { wechatKeyword.setCreateTime(new Date()); @@ -58,10 +59,32 @@ public class WechatRuleServiceImpl extends BaseServiceImpl implement wechatKeyword.setStatus(StatusTypeEnum.STATUS_ACTIVITY_YES.getValue()); 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()); + wechatRuleDao.save(wechatRule); + List 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; } + @Override public List findByWechatInfoId(Long wechatInfoId) { List wechatRuleVos = new ArrayList<>(); diff --git a/src/main/java/com/lq/cms/web/wechat/WechatMessageController.java b/src/main/java/com/lq/cms/web/wechat/WechatMessageController.java index b432b7a..afc6e17 100755 --- a/src/main/java/com/lq/cms/web/wechat/WechatMessageController.java +++ b/src/main/java/com/lq/cms/web/wechat/WechatMessageController.java @@ -5,12 +5,15 @@ import com.lq.cms.service.AdminBaseService; import com.lq.cms.service.WechatMessageService; import com.lq.cms.vo.WechatMessageVo; import com.lq.cms.web.AdminBaseController; +import com.lq.code.entity.AjaxResult; import com.lq.entity.WechatMessage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import java.util.List; import java.util.Map; /** @@ -40,7 +43,14 @@ public class WechatMessageController extends AdminBaseController wechatMessageVoList = wechatMessageService.findAllWechatMessageVo(); + AjaxResult ajaxResult = new AjaxResult(); + ajaxResult.setData(wechatMessageVoList); + return ajaxResult; + } @Override public AdminBaseService getBaseService() { diff --git a/src/main/java/com/lq/cms/web/wechat/WechatRuleController.java b/src/main/java/com/lq/cms/web/wechat/WechatRuleController.java index b67dcd6..3edf6d2 100755 --- a/src/main/java/com/lq/cms/web/wechat/WechatRuleController.java +++ b/src/main/java/com/lq/cms/web/wechat/WechatRuleController.java @@ -7,10 +7,9 @@ import com.lq.cms.service.WechatInfoService; import com.lq.cms.service.WechatRuleService; import com.lq.cms.vo.WechatRuleVo; 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.WechatKeyword; -import com.lq.entity.WechatRule; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -62,10 +61,11 @@ public class WechatRuleController { @RequestMapping("/save") public Object save(WechatRuleVo vo,String keywordListStr,String messageListStr,Long wechatInfoId){ AjaxResult ajaxResult = new AjaxResult(); - WechatRule wechatRule = new WechatRule(); - List wechatKeywordList = JSON.parseArray(keywordListStr,WechatKeyword.class); - BeanUtil.copyNotNull(wechatRule,vo); - wechatRuleService.saveRuleAndkeyword(wechatRule,wechatKeywordList); + if (StringUtil.isNotNull(keywordListStr)) { + List wechatKeywordList = JSON.parseArray(keywordListStr, WechatKeyword.class); + vo.setWechatKeywordList(wechatKeywordList); + } + wechatRuleService.saveRule(vo); return ajaxResult; } diff --git a/src/main/webapp/WEB-INF/views/jsp/cms/wechat/rule/index.jsp b/src/main/webapp/WEB-INF/views/jsp/cms/wechat/rule/index.jsp index eb65215..a44c26a 100755 --- a/src/main/webapp/WEB-INF/views/jsp/cms/wechat/rule/index.jsp +++ b/src/main/webapp/WEB-INF/views/jsp/cms/wechat/rule/index.jsp @@ -265,7 +265,6 @@ return ; } wechatKeyWord.keyword = keywordContent; - wechatKeyWord.matchinType = matchinType; keywordObjeList.push(wechatKeyWord); }); @@ -277,7 +276,6 @@ var messageList = new Array(); messageSet.forEach(function (element, sameElement, set) { messageList.push(element); - // messageList.push(e); }); messageSet.clear(); @@ -393,7 +391,7 @@ data.messageType = 'text-image'; $.ajax({ type:"post", - url:"${ctx}/admin/wechat/getMessageDataList.htm", + url:"${ctx}/cms/wechat/message/findMessageDataList", traditional:true, data:data, async:false, @@ -637,7 +635,7 @@ function appendAlertHtml(data){ var isShow ; - var wechatMessageList = data.wechatMessagList; + var wechatMessageList = data; var html = '

图文('+data.wechatMessageCount+')

'; html += '
'; for(var i = 0 ;i < wechatMessageList.length;i++){