|
@@ -8,9 +8,12 @@ import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
import com.liangjian11.wx.mp.mapper.KeywordMapper;
|
|
|
import com.liangjian11.wx.mp.modle.Keyword;
|
|
|
import com.liangjian11.wx.mp.service.KeywordService;
|
|
|
+import com.liangjian11.wx.mp.utils.ResultInfo;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -28,15 +31,6 @@ public class KeywordServiceImpl extends ServiceImpl<KeywordMapper, Keyword> impl
|
|
|
return keywordMapper.selectById(Id);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public int getKeywordByKeyword(String keyword,Integer parentId,String appId) {
|
|
|
- QueryWrapper<Keyword> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.eq("keyword",keyword);
|
|
|
- wrapper.eq("parentId",parentId);
|
|
|
- wrapper.eq("appId",appId);
|
|
|
- return keywordMapper.selectCount(wrapper);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public int editKeyword(Keyword keyword) {
|
|
|
return keywordMapper.updateById(keyword);
|
|
@@ -52,17 +46,69 @@ public class KeywordServiceImpl extends ServiceImpl<KeywordMapper, Keyword> impl
|
|
|
return keywordMapper.deleteById(id);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public int getKeywordByKeyword(String keyword,Integer parentId,String appId,Integer rank) {
|
|
|
+ QueryWrapper<Keyword> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("keyword",keyword);
|
|
|
+ wrapper.eq("parentId",parentId);
|
|
|
+ wrapper.eq("appId",appId);
|
|
|
+ wrapper.eq("rank",rank);
|
|
|
+ return keywordMapper.selectCount(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultInfo addKeyword(String appId, Keyword keyword) {
|
|
|
+ if(StringUtils.isBlank(appId)){
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_FAIL,2002,"appid不能为空");
|
|
|
+ }
|
|
|
+ //判断是否已经存在此关键字
|
|
|
+ if(this.getKeywordByKeyword(keyword.getKeyword(),keyword.getParentId(),appId,keyword.getRank())>0){
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_FAIL,333,"此关键字已存在");
|
|
|
+ }else {
|
|
|
+ keyword.setAppId(appId);
|
|
|
+ if(this.insert(keyword)>0){
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_SUCCESS,111,"添加关键字成功");
|
|
|
+ }
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_FAIL,222,"添加关键字失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultInfo checkBatchInsert(List<Keyword> keywordList, String appId) {
|
|
|
+ int num = 0;
|
|
|
+ //判断输入的关键词是否存在相同
|
|
|
+ if(keywordList.size()>2){
|
|
|
+ for(int i=0;i<keywordList.size()-1;i++){
|
|
|
+ for(int j=0;j<keywordList.size()-i-1;j++){
|
|
|
+ if(keywordList.get(j).getKeyword().equals(keywordList.get(j+1).getKeyword())&&keywordList.get(j).getRank().equals(keywordList.get(j+1).getRank())){
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_FAIL,444,"重复输入关键词"+keywordList.get(j).getKeyword());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断输入的关键词在数据库中是否已经存在
|
|
|
+ for (Keyword keyword : keywordList) {
|
|
|
+ int i = this.getKeywordByKeyword(keyword.getKeyword(), keyword.getParentId(), appId, keyword.getRank());
|
|
|
+ if(i>0){
|
|
|
+ num++;
|
|
|
+ }
|
|
|
+ if(num>0){return new ResultInfo(ResultInfo.TYPE_RESULT_FAIL,333,"关键词或规则"+keyword.getKeyword()+"已经存在");}
|
|
|
+ }
|
|
|
+ //如果没有重复执行插入
|
|
|
+ if(num==0){
|
|
|
+ for (Keyword keyword : keywordList) {
|
|
|
+ keyword.setAppId(appId);
|
|
|
+ keywordMapper.insert(keyword);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new ResultInfo(ResultInfo.TYPE_RESULT_SUCCESS,111,"添加关键字成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public List<Keyword> getKeywordByParentId(int parentId) {
|
|
|
return keywordMapper.selectList(new QueryWrapper<Keyword>().eq("parentId",parentId));
|
|
|
}
|
|
|
|
|
|
- /* @Override
|
|
|
- public List<Keyword> getKeywordPageList(int start, int pageSize) {
|
|
|
- IPage<Map<String, Object>> mapIPage = keywordMapper.selectMapsPage(new Page<Keyword>(start, pageSize), null);
|
|
|
- List<Map<String, Object>> records = mapIPage.getRecords();
|
|
|
- for (Map<String, Object> record : records) {
|
|
|
- }
|
|
|
- return null;
|
|
|
- }*/
|
|
|
+
|
|
|
}
|