Commit a2724d90 authored by 赵啸非's avatar 赵啸非

修改热门词汇

parent bc92650f
Pipeline #2412 canceled with stages
...@@ -45,13 +45,24 @@ public class BasesetServiceImpl extends AbstractCRUDServiceImpl<BasesetDao, Base ...@@ -45,13 +45,24 @@ public class BasesetServiceImpl extends AbstractCRUDServiceImpl<BasesetDao, Base
@Override @Override
protected void saveAfter(BasesetEntity entity, Context context) throws AppException { protected void saveAfter(BasesetEntity entity, Context context) throws AppException {
updateAndSaveHotWords(entity, context);
super.saveAfter(entity, context);
}
@Override
protected void updateAfter(BasesetEntity entity, Context context) throws AppException {
updateAndSaveHotWords(entity, context);
super.updateAfter(entity, context);
}
private void updateAndSaveHotWords(BasesetEntity entity, Context context) {
if(!ObjectUtils.isEmpty(entity.getHotwordList())){ if(!ObjectUtils.isEmpty(entity.getHotwordList())){
//更新新增热门词汇,差集删除不在列表中的 //更新新增热门词汇,差集删除不在列表中的
List<HotwordEntity> allHotWords = hotwordService.find(new HotwordQuery().siteId(entity.getSiteId())); List<HotwordEntity> allHotWords = hotwordService.find(new HotwordQuery().siteId(entity.getSiteId()));
//求差集 删除 //求差集 删除
List<HotwordEntity> delList = this.subList(allHotWords, entity.getHotwordList()); List<HotwordEntity> delList = this.subList(allHotWords, entity.getHotwordList());
if(!ObjectUtils.isEmpty(delList)){ if(!ObjectUtils.isEmpty(delList)){
hotwordService.removeList(delList,context); hotwordService.removeList(delList, context);
} }
entity.getHotwordList().forEach(item -> { entity.getHotwordList().forEach(item -> {
HotwordEntity hotwordEntity = hotwordService.selectOne(new HotwordQuery().siteId(item.getSiteId()).hotwords(item.getHotwords())); HotwordEntity hotwordEntity = hotwordService.selectOne(new HotwordQuery().siteId(item.getSiteId()).hotwords(item.getHotwords()));
...@@ -59,21 +70,18 @@ public class BasesetServiceImpl extends AbstractCRUDServiceImpl<BasesetDao, Base ...@@ -59,21 +70,18 @@ public class BasesetServiceImpl extends AbstractCRUDServiceImpl<BasesetDao, Base
item.setId(hotwordEntity.getId()); item.setId(hotwordEntity.getId());
item.setSearchCount(hotwordEntity.getSearchCount()); item.setSearchCount(hotwordEntity.getSearchCount());
item.setUpdateTime(new Date()); item.setUpdateTime(new Date());
hotwordService.update(item,context); hotwordService.update(item, context);
}else{ }else{
item.setCreateUserId(this.getContextUserId(context)); item.setCreateUserId(this.getContextUserId(context));
item.setCreateTime(new Date()); item.setCreateTime(new Date());
hotwordService.save(item,context); hotwordService.save(item, context);
} }
}); });
} }
super.saveAfter(entity, context);
} }
public List<HotwordEntity> subList(List<HotwordEntity> firstList, List<HotwordEntity> secondList) { public List<HotwordEntity> subList(List<HotwordEntity> firstList, List<HotwordEntity> secondList) {
Set<String> secondSet = secondList.parallelStream().map(e -> e.getHotwords()).collect(Collectors.toSet()); Set<String> secondSet = secondList.parallelStream().map(e -> e.getHotwords()).collect(Collectors.toSet());
return firstList.parallelStream().filter(item -> !secondSet.contains(item.getHotwords())).collect(Collectors.toList()); return firstList.parallelStream().filter(item -> !secondSet.contains(item.getHotwords())).collect(Collectors.toList());
......
package com.mortals.xhx.module.baseset.web; package com.mortals.xhx.module.baseset.web;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService; import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.common.code.NewsSourceEnum; import com.mortals.xhx.common.code.NewsSourceEnum;
import com.mortals.xhx.module.baseset.model.BasesetQuery;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -18,15 +21,11 @@ import com.mortals.xhx.module.baseset.service.BasesetService; ...@@ -18,15 +21,11 @@ import com.mortals.xhx.module.baseset.service.BasesetService;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -53,4 +52,16 @@ public class BasesetController extends BaseCRUDJsonBodyMappingController<Baseset ...@@ -53,4 +52,16 @@ public class BasesetController extends BaseCRUDJsonBodyMappingController<Baseset
} }
@Override
protected void saveBefore(BasesetEntity entity, Map<String, Object> model, Context context) throws AppException {
BasesetEntity basesetEntity = this.service.selectOne(new BasesetQuery().siteId(entity.getSiteId()));
if(!ObjectUtils.isEmpty(basesetEntity)){
entity.setId(basesetEntity.getId());
entity.setUpdateTime(new Date());
}
super.saveBefore(entity, model, context);
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment