|
@@ -45,130 +45,142 @@ import java.util.List;
|
|
|
@RequestMapping(value = "${adminPath}/product/keywordFrequency")
|
|
|
public class KeywordFrequencyController extends BaseController {
|
|
|
|
|
|
- @Autowired
|
|
|
- private KeywordFrequencyService keywordFrequencyService;
|
|
|
+ @Autowired
|
|
|
+ private KeywordFrequencyService keywordFrequencyService;
|
|
|
|
|
|
/**
|
|
|
* 查询未加入关键词库的数据
|
|
|
+ *
|
|
|
* @param searchFrequency
|
|
|
* @param request
|
|
|
* @param response
|
|
|
* @param model
|
|
|
* @return
|
|
|
*/
|
|
|
- @RequestMapping(value="/getKeyInfo")
|
|
|
- public String getKeyInfo(SearchFrequency searchFrequency, HttpServletRequest request, HttpServletResponse response, Model model){//@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
- searchFrequency.setTrueStatus(0);
|
|
|
- Page<SearchFrequency> keyInfo = keywordFrequencyService.findPage(new Page<SearchFrequency>(request,response),searchFrequency);
|
|
|
- List<SearchFrequency> seacherFrom = keywordFrequencyService.getSearchFrom(1);
|
|
|
- model.addAttribute("keyInfo",keyInfo);
|
|
|
- model.addAttribute("searchFrequency",searchFrequency);
|
|
|
- model.addAttribute("seacherFrom",seacherFrom);
|
|
|
- return "modules/product/keywordFrequency";
|
|
|
- }
|
|
|
+ @RequestMapping(value = "/getKeyInfo")
|
|
|
+ public String getKeyInfo(SearchFrequency searchFrequency, HttpServletRequest request, HttpServletResponse response, Model model) {//@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
+ searchFrequency.setTrueStatus(0);
|
|
|
+ Page<SearchFrequency> keyInfo = keywordFrequencyService.findPage(new Page<SearchFrequency>(request, response), searchFrequency);
|
|
|
+ List<SearchFrequency> seacherFrom = keywordFrequencyService.getSearchFrom(1);
|
|
|
+ model.addAttribute("keyInfo", keyInfo);
|
|
|
+ model.addAttribute("searchFrequency", searchFrequency);
|
|
|
+ model.addAttribute("seacherFrom", seacherFrom);
|
|
|
+ return "modules/product/keywordFrequency";
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询已加入关键词库的数据
|
|
|
+ *
|
|
|
* @param searchFrequency
|
|
|
* @param request
|
|
|
* @param response
|
|
|
* @param model
|
|
|
* @return
|
|
|
*/
|
|
|
- @RequestMapping(value="/getKeywordThesaurusInfo")
|
|
|
- public String getKeywordThesaurusInfo(SearchFrequency searchFrequency, HttpServletRequest request, HttpServletResponse response, Model model){//@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
+ @RequestMapping(value = "/getKeywordThesaurusInfo")
|
|
|
+ public String getKeywordThesaurusInfo(SearchFrequency searchFrequency, HttpServletRequest request, HttpServletResponse response, Model model) {//@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
searchFrequency.setTrueStatus(1);
|
|
|
- Page<SearchFrequency> keyInfo = keywordFrequencyService.findPage(new Page<SearchFrequency>(request,response),searchFrequency);
|
|
|
+ Page<SearchFrequency> keyInfo = keywordFrequencyService.findPage(new Page<SearchFrequency>(request, response), searchFrequency);
|
|
|
List<SearchFrequency> list = keyInfo.getList();
|
|
|
- for (SearchFrequency search:list) {
|
|
|
- if(null != search.getSearchTime()){
|
|
|
+ for (SearchFrequency search : list) {
|
|
|
+ if (null != search.getSearchTime()) {
|
|
|
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- Date da=new Date(search.getSearchTime().getTime());
|
|
|
+ Date da = new Date(search.getSearchTime().getTime());
|
|
|
String date = fmt.format(da);
|
|
|
search.setSerachDate(date);
|
|
|
}
|
|
|
}
|
|
|
keyInfo.setList(list);
|
|
|
List<SearchFrequency> seacherFrom = keywordFrequencyService.getSearchFrom(2);
|
|
|
- model.addAttribute("keyInfo",keyInfo);
|
|
|
- model.addAttribute("searchFrequency",searchFrequency);
|
|
|
- model.addAttribute("seacherFrom",seacherFrom);
|
|
|
+ model.addAttribute("keyInfo", keyInfo);
|
|
|
+ model.addAttribute("searchFrequency", searchFrequency);
|
|
|
+ model.addAttribute("seacherFrom", seacherFrom);
|
|
|
return "modules/product/keywordThesaurus";
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 查询未加入关键词库的关键词来源
|
|
|
- * @return
|
|
|
- */
|
|
|
- @ResponseBody
|
|
|
- @RequestMapping("/getSeacherFrom")
|
|
|
- public List<String> getSearchFrom(Integer trueStatus){
|
|
|
+ /**
|
|
|
+ * 查询未加入关键词库的关键词来源
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping("/getSeacherFrom")
|
|
|
+ public List<String> getSearchFrom(Integer trueStatus) {
|
|
|
// List<String> seacherFrom = keywordFrequencyService.getSearchFrom(trueStatus);
|
|
|
- return null;
|
|
|
- }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 加入关键词库
|
|
|
+ *
|
|
|
* @param ids
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping("/addKeyWordList")
|
|
|
@ResponseBody
|
|
|
- public String addKeyWordList(String ids,Model model){
|
|
|
+ public String addKeyWordList(String ids, Model model) {
|
|
|
keywordFrequencyService.addKeyWordList(ids);
|
|
|
return "success";
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 验证关键词库是该否存在关键词
|
|
|
+ *
|
|
|
* @param keyword
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping("/verificationKeword")
|
|
|
@ResponseBody
|
|
|
- public String verificationKeword(String keyword,Model model){
|
|
|
+ public String verificationKeword(String keyword, Model model) {
|
|
|
boolean b = keywordFrequencyService.verificationKeword(keyword);
|
|
|
- if(b){
|
|
|
+ if (b) {
|
|
|
return "-1";
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return "0";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 验证关键词库是该否存在关键词
|
|
|
+ *
|
|
|
* @param keywords
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping("/verificationKewords")
|
|
|
@ResponseBody
|
|
|
- public String verificationKewords(String keywords,Model model){
|
|
|
+ public String verificationKewords(String keywords, Model model) {
|
|
|
boolean b = keywordFrequencyService.verificationKewords(keywords);
|
|
|
- if(b){
|
|
|
+ if (b) {
|
|
|
return "-1";
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return "0";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 删除关键词
|
|
|
* status 区分是关键词界面还是关键词库界面 (1关键词;2关键词库)
|
|
|
+ *
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping("/delKeyWordById")
|
|
|
- public String delKeyWordById(Integer id,Integer status,RedirectAttributes redirectAttributes){
|
|
|
- keywordFrequencyService.delKeyWordById(id,status);
|
|
|
+ public String delKeyWordById(Integer id, Integer status, RedirectAttributes redirectAttributes) {
|
|
|
+ keywordFrequencyService.delKeyWordById(id, status);
|
|
|
addMessage(redirectAttributes, "删除关键词成功");
|
|
|
- if(status==1){
|
|
|
- return "redirect:"+Global.getAdminPath()+"/product/keywordFrequency/getKeyInfo";
|
|
|
+ if (status == 1) {
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/product/keywordFrequency/getKeyInfo";
|
|
|
|
|
|
}
|
|
|
- return "redirect:"+Global.getAdminPath()+"/product/keywordFrequency/getKeywordThesaurusInfo";
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/product/keywordFrequency/getKeywordThesaurusInfo";
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 跳转编辑添加页面
|
|
|
+ *
|
|
|
* @param searchFrequency
|
|
|
* @param model
|
|
|
* @return
|
|
@@ -181,51 +193,53 @@ public class KeywordFrequencyController extends BaseController {
|
|
|
|
|
|
/**
|
|
|
* 更新关键词
|
|
|
+ *
|
|
|
* @param searchFrequency
|
|
|
* @param redirectAttributes
|
|
|
* @param model
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping("save")
|
|
|
- public String save(SearchFrequency searchFrequency,RedirectAttributes redirectAttributes,Model model){
|
|
|
- if (!beanValidator(model, searchFrequency)){
|
|
|
+ public String save(SearchFrequency searchFrequency, RedirectAttributes redirectAttributes, Model model) {
|
|
|
+ if (!beanValidator(model, searchFrequency)) {
|
|
|
return form(searchFrequency, model);
|
|
|
}
|
|
|
//如果是新增操作时
|
|
|
searchFrequency.setTrueStatus(1);
|
|
|
searchFrequency.setFromSearch(6);//为管理员添加
|
|
|
searchFrequency.setPath("管理员添加");
|
|
|
- Date date=new Date();
|
|
|
- SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Date date = new Date();
|
|
|
+ SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
sd.format(date);
|
|
|
// searchFrequency.setSearchTime(new java.sql.Timestamp(date.getTime()));
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
cal.setTime(date);
|
|
|
searchFrequency.setSearchTime(new java.sql.Timestamp(cal.getTime().getTime()));
|
|
|
|
|
|
- if(null !=searchFrequency.getKeyId()){
|
|
|
+ if (null != searchFrequency.getKeyId()) {
|
|
|
searchFrequency.setId(searchFrequency.getKeyId().toString());
|
|
|
}
|
|
|
keywordFrequencyService.save(searchFrequency);
|
|
|
- if(searchFrequency.getStatus()==2){
|
|
|
+ if (searchFrequency.getStatus() == 2) {
|
|
|
//保存后重置关键词redis缓存
|
|
|
keywordFrequencyService.cacheKeyWord();
|
|
|
- List<SearchFrequency> list=new ArrayList<>();
|
|
|
+ List<SearchFrequency> list = new ArrayList<>();
|
|
|
list.add(searchFrequency);
|
|
|
keywordFrequencyService.conKeyWord(list);
|
|
|
}
|
|
|
addMessage(redirectAttributes, "保存成功");
|
|
|
//编辑
|
|
|
- if(null !=searchFrequency.getStatus()&&1==searchFrequency.getStatus()){
|
|
|
- return "redirect:"+Global.getAdminPath()+"/product/keywordFrequency/getKeyInfo";
|
|
|
+ if (null != searchFrequency.getStatus() && 1 == searchFrequency.getStatus()) {
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/product/keywordFrequency/getKeyInfo";
|
|
|
}
|
|
|
//新增
|
|
|
- return "redirect:"+Global.getAdminPath()+"/product/keywordFrequency/getKeywordThesaurusInfo";
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/product/keywordFrequency/getKeywordThesaurusInfo";
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 导出关键词
|
|
|
+ *
|
|
|
* @param ids
|
|
|
* @param redirectAttributes
|
|
|
* @param request
|
|
@@ -249,8 +263,10 @@ public class KeywordFrequencyController extends BaseController {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 导出关键词库关键词
|
|
|
+ *
|
|
|
* @param ids
|
|
|
* @param redirectAttributes
|
|
|
* @param request
|
|
@@ -277,22 +293,23 @@ public class KeywordFrequencyController extends BaseController {
|
|
|
|
|
|
/**
|
|
|
* 导入关键词
|
|
|
+ *
|
|
|
* @param file
|
|
|
* @param redirectAttributes
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "importKeyword")
|
|
|
- public String importKeyword(@RequestParam("file") MultipartFile file, RedirectAttributes redirectAttributes){
|
|
|
+ public String importKeyword(@RequestParam("file") MultipartFile file, RedirectAttributes redirectAttributes) {
|
|
|
String contentType = file.getContentType();
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
if (file.isEmpty()) {
|
|
|
- addMessage(redirectAttributes,"请选择需要导入的关键词文件");
|
|
|
- return "redirect:"+Global.getAdminPath()+"/product/keywordFrequency/getKeywordThesaurusInfo";
|
|
|
+ addMessage(redirectAttributes, "请选择需要导入的关键词文件");
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/product/keywordFrequency/getKeywordThesaurusInfo";
|
|
|
}
|
|
|
- int sum=0;//总数量
|
|
|
- int falseNum=0;//已存在数量
|
|
|
- int successNum=0;
|
|
|
- String falseKeys="";//已存在关键词
|
|
|
+ int sum = 0;//总数量
|
|
|
+ int falseNum = 0;//已存在数量
|
|
|
+ int successNum = 0;
|
|
|
+ String falseKeys = "";//已存在关键词
|
|
|
try {
|
|
|
//根据路径获取这个操作excel的实例
|
|
|
HSSFWorkbook wb = new HSSFWorkbook(file.getInputStream());
|
|
@@ -300,33 +317,33 @@ public class KeywordFrequencyController extends BaseController {
|
|
|
HSSFSheet sheet = wb.getSheetAt(0);
|
|
|
HSSFRow row = null;
|
|
|
//循环sesheet页中数据从第二行开始,第一行是标题
|
|
|
- List<SearchFrequency> searchFrequencyList=new ArrayList<>();
|
|
|
- sum=sheet.getPhysicalNumberOfRows()-1;
|
|
|
- for(int i=1;i<=sheet.getPhysicalNumberOfRows()-1;i++){
|
|
|
+ List<SearchFrequency> searchFrequencyList = new ArrayList<>();
|
|
|
+ sum = sheet.getPhysicalNumberOfRows() - 1;
|
|
|
+ for (int i = 1; i <= sheet.getPhysicalNumberOfRows() - 1; i++) {
|
|
|
row = sheet.getRow(i);
|
|
|
- SearchFrequency searchFrequency=new SearchFrequency();
|
|
|
+ SearchFrequency searchFrequency = new SearchFrequency();
|
|
|
//关键词
|
|
|
- if(null !=row.getCell(1)){
|
|
|
- searchFrequency.setKeyword(row.getCell(1).toString());
|
|
|
+ if (null != row.getCell(1)) {
|
|
|
+ searchFrequency.setKeyword(row.getCell(1).toString());
|
|
|
boolean b = keywordFrequencyService.verificationKeword(row.getCell(1).toString());
|
|
|
- if(b){//判断关键词是否已存在
|
|
|
- falseNum+=1;
|
|
|
- if(StringUtils.isNotEmpty(falseKeys)){
|
|
|
- falseKeys=falseKeys+","+row.getCell(1).toString();
|
|
|
- }else{
|
|
|
- falseKeys+=row.getCell(1).toString();
|
|
|
+ if (b) {//判断关键词是否已存在
|
|
|
+ falseNum += 1;
|
|
|
+ if (StringUtils.isNotEmpty(falseKeys)) {
|
|
|
+ falseKeys = falseKeys + "," + row.getCell(1).toString();
|
|
|
+ } else {
|
|
|
+ falseKeys += row.getCell(1).toString();
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
continue;
|
|
|
}
|
|
|
//联动次数
|
|
|
- if(null !=row.getCell(2)){
|
|
|
- String linkageFrequency= row.getCell(2).toString();
|
|
|
- if(linkageFrequency.indexOf(".")>0){
|
|
|
- linkageFrequency=linkageFrequency.replace(".","");
|
|
|
- }
|
|
|
+ if (null != row.getCell(2)) {
|
|
|
+ String linkageFrequency = row.getCell(2).toString();
|
|
|
+ if (linkageFrequency.indexOf(".") > 0) {
|
|
|
+ linkageFrequency = linkageFrequency.replace(".", "");
|
|
|
+ }
|
|
|
searchFrequency.setLinkageFrequency(Integer.valueOf(linkageFrequency));
|
|
|
}
|
|
|
// if(null != row.getCell(2)){
|
|
@@ -339,23 +356,23 @@ public class KeywordFrequencyController extends BaseController {
|
|
|
// }
|
|
|
// }
|
|
|
//添加时间
|
|
|
- if(null != row.getCell(3)){
|
|
|
+ if (null != row.getCell(3)) {
|
|
|
searchFrequency.setSearchTime(new java.sql.Timestamp(row.getCell(3).getDateCellValue().getTime()));
|
|
|
}
|
|
|
searchFrequency.setPath("管理员添加");
|
|
|
searchFrequency.setTrueStatus(1);
|
|
|
searchFrequencyList.add(searchFrequency);
|
|
|
}
|
|
|
- successNum=sum-falseNum;
|
|
|
+ successNum = sum - falseNum;
|
|
|
//保存文件数据
|
|
|
keywordFrequencyService.importKeyword(searchFrequencyList);
|
|
|
//保存后重置关键词redis缓存
|
|
|
keywordFrequencyService.cacheKeyWord();
|
|
|
keywordFrequencyService.conKeyWord(searchFrequencyList);
|
|
|
- } catch (IOException e) {//| ParseException
|
|
|
+ } catch (IOException e) {//| ParseException
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- addMessage(redirectAttributes,"导入关键词成功:总数: "+sum+" 条 其中成功 " +successNum+" 条"+"; 关键词库已存在: "+falseNum+" 条( "+falseKeys+" )");
|
|
|
- return "redirect:"+Global.getAdminPath()+"/product/keywordFrequency/getKeywordThesaurusInfo";
|
|
|
+ addMessage(redirectAttributes, "导入关键词成功:总数: " + sum + " 条 其中成功 " + successNum + " 条" + "; 关键词库已存在: " + falseNum + " 条( " + falseKeys + " )");
|
|
|
+ return "redirect:" + Global.getAdminPath() + "/product/keywordFrequency/getKeywordThesaurusInfo";
|
|
|
}
|
|
|
}
|