|
@@ -2,8 +2,13 @@ package com.liangjian11.wx.mp.controller;
|
|
|
|
|
|
|
|
|
import com.liangjian11.wx.mp.modle.Keyword;
|
|
|
+import com.liangjian11.wx.mp.modle.KeywordMessageRef;
|
|
|
import com.liangjian11.wx.mp.modle.Result;
|
|
|
+import com.liangjian11.wx.mp.service.KeywordMessageRefService;
|
|
|
import com.liangjian11.wx.mp.service.KeywordService;
|
|
|
+import com.liangjian11.wx.mp.service.MessageService;
|
|
|
+import com.liangjian11.wx.mp.utils.ResultInfo;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
@@ -18,27 +23,29 @@ import java.util.List;
|
|
|
public class WxKeywordController {
|
|
|
@Autowired
|
|
|
private KeywordService keywordService;
|
|
|
+ @Autowired
|
|
|
+ private KeywordMessageRefService keywordMessageRefService;
|
|
|
|
|
|
/**
|
|
|
* 添加关键字
|
|
|
* @param keyword
|
|
|
* @return
|
|
|
*/
|
|
|
- @PostMapping("/add")
|
|
|
- public Result addKeyword(@RequestBody Keyword keyword){
|
|
|
- Result result = new Result();
|
|
|
+ @PostMapping("/add/{appid}")
|
|
|
+ public ResultInfo addKeyword(@PathVariable String appid,@RequestBody Keyword keyword){
|
|
|
+ if(StringUtils.isBlank(appid)){
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_FAIL,2002,"appid不能为空");
|
|
|
+ }
|
|
|
//判断是否已经存在此关键字
|
|
|
- if(keywordService.getKeywordByKeyword(keyword.getKeyword(),keyword.getParentId(),keyword.getAppId())>0){
|
|
|
- result.setCode("111");
|
|
|
- result.setMsg("此关键字已经存在");
|
|
|
+ if(keywordService.getKeywordByKeyword(keyword.getKeyword(),keyword.getParentId(),appid)>0){
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_FAIL,333,"此关键字已存在");
|
|
|
}else {
|
|
|
- int add = keywordService.insert(keyword);
|
|
|
- if(add>0){
|
|
|
- result.setCode("222");
|
|
|
- result.setMsg("添加关键字成功");
|
|
|
+ keyword.setAppId(appid);
|
|
|
+ if(keywordService.insert(keyword)>0){
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_SUCCESS,111,"添加关键字成功");
|
|
|
}
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_FAIL,222,"添加关键字失败");
|
|
|
}
|
|
|
- return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -57,9 +64,47 @@ public class WxKeywordController {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询规则ID对应的关键词
|
|
|
+ * @param parentId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@GetMapping("/finds")
|
|
|
public List<Keyword> getKeywordByParentId(Integer parentId){
|
|
|
return keywordService.getKeywordByParentId(parentId);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更改规则发送消息关系
|
|
|
+ * @param keywordMessageRef
|
|
|
+ */
|
|
|
+ @PostMapping("/update")
|
|
|
+ public ResultInfo updateById(@RequestBody KeywordMessageRef keywordMessageRef){
|
|
|
+ keywordMessageRefService.updateById(keywordMessageRef);
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_SUCCESS,111,"修改成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 插入规则对应消息关系
|
|
|
+ * @param keywordMessageRef
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/insert")
|
|
|
+ public ResultInfo insert(@RequestBody KeywordMessageRef keywordMessageRef){
|
|
|
+ if(keywordMessageRef.getMessageId()==null){
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_FAIL,2002,"推送消息ID不能为空");
|
|
|
+ }
|
|
|
+ if(keywordMessageRef.getKeyWordId()==null){
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_FAIL,2002,"规则ID不能为空");
|
|
|
+ }
|
|
|
+ if(keywordMessageRefService.selectCount(keywordMessageRef.getKeyWordId(),keywordMessageRef.getMessageId())>0){
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_FAIL,333,"规则对应发送消息关系已经存在,请勿重复添加");
|
|
|
+ }else if(keywordMessageRefService.insert(keywordMessageRef)>0){
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_SUCCESS,111,"添加成功");
|
|
|
+ }else {
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_FAIL,222,"添加失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|