|
@@ -0,0 +1,318 @@
|
|
|
+package com.caimei.modules.product.web;
|
|
|
+
|
|
|
+import com.caimei.modules.common.utils.ExcelUtil;
|
|
|
+import com.caimei.modules.order.entity.CmAuthorizedConsignment;
|
|
|
+import com.caimei.modules.order.entity.CmDiscernReceipt;
|
|
|
+import com.caimei.modules.order.utils.OrderUtil;
|
|
|
+import com.caimei.modules.product.entity.SearchFrequency;
|
|
|
+import com.caimei.modules.product.entity.SearchFrequencyVo;
|
|
|
+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;
|
|
|
+import org.springframework.ui.Model;
|
|
|
+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.io.IOException;
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Controller
|
|
|
+@RequestMapping(value = "${adminPath}/product/keywordFrequency")
|
|
|
+public class KeywordFrequencyController extends BaseController {
|
|
|
+
|
|
|
+ @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";
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 查询已加入关键词库的数据
|
|
|
+ * @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,
|
|
|
+ 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);
|
|
|
+ List<SearchFrequency> seacherFrom = keywordFrequencyService.getSearchFrom(2);
|
|
|
+ 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){
|
|
|
+// List<String> seacherFrom = keywordFrequencyService.getSearchFrom(trueStatus);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加入关键词库
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping("/addKeyWordList")
|
|
|
+ @ResponseBody
|
|
|
+ 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){
|
|
|
+ boolean b = keywordFrequencyService.verificationKeword(keyword);
|
|
|
+ if(b){
|
|
|
+ return "-1";
|
|
|
+ }else{
|
|
|
+ return "0";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 删除关键词
|
|
|
+ * status 区分是关键词界面还是关键词库界面 (1关键词;2关键词库)
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping("/delKeyWordById")
|
|
|
+ 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";
|
|
|
+
|
|
|
+ }
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/product/keywordFrequency/getKeywordThesaurusInfo";
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转编辑添加页面
|
|
|
+ * @param searchFrequency
|
|
|
+ * @param model
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "form")
|
|
|
+ public String form(SearchFrequency searchFrequency, Model model) {
|
|
|
+ model.addAttribute("searchFrequency", searchFrequency);
|
|
|
+ return "modules/product/upkeyword";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新关键词
|
|
|
+ * @param searchFrequency
|
|
|
+ * @param redirectAttributes
|
|
|
+ * @param model
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping("save")
|
|
|
+ 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");
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ keywordFrequencyService.save(searchFrequency);
|
|
|
+ if(searchFrequency.getStatus()==2){
|
|
|
+ //保存后重置关键词redis缓存
|
|
|
+ keywordFrequencyService.cacheKeyWord();
|
|
|
+ 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";
|
|
|
+ }
|
|
|
+ //新增
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/product/keywordFrequency/getKeywordThesaurusInfo";
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出关键词
|
|
|
+ * @param ids
|
|
|
+ * @param redirectAttributes
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "export")
|
|
|
+ public void export(String ids, RedirectAttributes redirectAttributes, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ //获取订单数据
|
|
|
+ String fileName = "关键词列表.xls";
|
|
|
+ String template = Global.getConfig("export.template");
|
|
|
+ String templateFileName = template + "/keyword.xls";
|
|
|
+ try {
|
|
|
+ Map data = new HashMap<String, Object>();
|
|
|
+ List<SearchFrequency> list = keywordFrequencyService.export(ids);
|
|
|
+ data.put("list", list);
|
|
|
+// data.put("orderUtil", new OrderUtil());
|
|
|
+ new ExcelUtil().createExcel(templateFileName, data, fileName, response);
|
|
|
+ } catch (Exception e) {
|
|
|
+ addMessage(redirectAttributes, "关键词导出失败!" + e.getMessage());
|
|
|
+ logger.info(e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 导出关键词库关键词
|
|
|
+ * @param ids
|
|
|
+ * @param redirectAttributes
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "exportThesaurus")
|
|
|
+ public void exportThesaurus(String ids, RedirectAttributes redirectAttributes, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ //获取订单数据
|
|
|
+ String fileName = "关键词列表.xls";
|
|
|
+ String template = Global.getConfig("export.template");
|
|
|
+ String templateFileName = template + "/thesaurus.xls";
|
|
|
+ try {
|
|
|
+ Map data = new HashMap<String, Object>();
|
|
|
+ List<SearchFrequency> list = keywordFrequencyService.export(ids);
|
|
|
+ data.put("list", list);
|
|
|
+// data.put("orderUtil", new OrderUtil());
|
|
|
+ new ExcelUtil().createExcel(templateFileName, data, fileName, response);
|
|
|
+ } catch (Exception e) {
|
|
|
+ addMessage(redirectAttributes, "关键词导出失败!" + e.getMessage());
|
|
|
+ logger.info(e.getMessage());
|
|
|
+ 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);
|
|
|
+ //保存后重置关键词redis缓存
|
|
|
+ keywordFrequencyService.cacheKeyWord();
|
|
|
+ keywordFrequencyService.conKeyWord(searchFrequencyList);
|
|
|
+ } catch (IOException e) {//| ParseException
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ addMessage(redirectAttributes,"导入的关键词成功");
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/product/keywordFrequency/getKeywordThesaurusInfo";
|
|
|
+ }
|
|
|
+}
|