|
@@ -9,7 +9,15 @@ import com.caimei.modules.product.service.KeywordFrequencyService;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.thinkgem.jeesite.common.config.Global;
|
|
|
import com.thinkgem.jeesite.common.persistence.Page;
|
|
|
+import com.thinkgem.jeesite.common.utils.DateUtils;
|
|
|
+import com.thinkgem.jeesite.common.utils.excel.ImportExcel;
|
|
|
import com.thinkgem.jeesite.common.web.BaseController;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
+import org.apache.poi.ss.usermodel.DateUtil;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
@@ -18,15 +26,18 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.awt.*;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
+import java.io.IOException;
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
@Controller
|
|
|
@RequestMapping(value = "${adminPath}/product/keywordFrequency")
|
|
@@ -63,6 +74,16 @@ public class KeywordFrequencyController extends BaseController {
|
|
|
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);
|
|
|
+ List<SearchFrequency> list = keyInfo.getList();
|
|
|
+ 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());
|
|
|
+ String date = fmt.format(da);
|
|
|
+ search.setSerachDate(date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ keyInfo.setList(list);
|
|
|
model.addAttribute("keyInfo",keyInfo);
|
|
|
model.addAttribute("searchFrequency",searchFrequency);
|
|
|
return "modules/product/keywordThesaurus";
|
|
@@ -138,7 +159,13 @@ public class KeywordFrequencyController extends BaseController {
|
|
|
searchFrequency.setFromSearch(6);//为管理员添加
|
|
|
searchFrequency.setPath("管理员添加");
|
|
|
Date date=new Date();
|
|
|
- searchFrequency.setSearchTime(new java.sql.Date(date.getTime()));
|
|
|
+ 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()){
|
|
|
searchFrequency.setId(searchFrequency.getKeyId().toString());
|
|
|
}
|
|
@@ -179,7 +206,7 @@ public class KeywordFrequencyController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
- * 导出关键词
|
|
|
+ * 导出关键词库关键词
|
|
|
* @param ids
|
|
|
* @param redirectAttributes
|
|
|
* @param request
|
|
@@ -203,4 +230,59 @@ public class KeywordFrequencyController extends BaseController {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入关键词
|
|
|
+ * @param file
|
|
|
+ * @param redirectAttributes
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "importKeyword")
|
|
|
+ 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";
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ //根据路径获取这个操作excel的实例
|
|
|
+ HSSFWorkbook wb = new HSSFWorkbook(file.getInputStream());
|
|
|
+ //根据页面index 获取sheet页
|
|
|
+ HSSFSheet sheet = wb.getSheetAt(0);
|
|
|
+ HSSFRow row = null;
|
|
|
+ //循环sesheet页中数据从第二行开始,第一行是标题
|
|
|
+ List<SearchFrequency> searchFrequencyList=new ArrayList<>();
|
|
|
+ for(int i=1;i<sheet.getPhysicalNumberOfRows()-1;i++){
|
|
|
+ row = sheet.getRow(i);
|
|
|
+ SearchFrequency searchFrequency=new SearchFrequency();
|
|
|
+ if(null !=row.getCell(1)){
|
|
|
+ searchFrequency.setKeyword(row.getCell(1).toString());
|
|
|
+ }else{
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(null != row.getCell(2)){
|
|
|
+ if("首页搜索".equals(row.getCell(2).toString())){
|
|
|
+ searchFrequency.setFromSearch(1);
|
|
|
+ }else if("信息中心搜索".equals(row.getCell(2).toString())){
|
|
|
+ searchFrequency.setFromSearch(2);
|
|
|
+ }else if("管理员添加".equals(row.getCell(2).toString())){
|
|
|
+ searchFrequency.setFromSearch(6);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(null != row.getCell(3)){
|
|
|
+ searchFrequency.setSearchTime(new java.sql.Timestamp(row.getCell(3).getDateCellValue().getTime()));
|
|
|
+ }
|
|
|
+ searchFrequency.setPath("管理员添加");
|
|
|
+ searchFrequency.setTrueStatus(1);
|
|
|
+ searchFrequencyList.add(searchFrequency);
|
|
|
+ }
|
|
|
+ //保存文件数据
|
|
|
+ keywordFrequencyService.importKeyword(searchFrequencyList);
|
|
|
+ } catch (IOException e) {//| ParseException
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ addMessage(redirectAttributes,"导入的关键词成功");
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/product/keywordFrequency/getKeywordThesaurusInfo";
|
|
|
+ }
|
|
|
}
|