|
@@ -24,10 +24,16 @@ import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
import org.jeecg.common.system.api.ISysBaseAPI;
|
|
|
import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
import org.jeecg.common.system.query.QueryGenerator;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
+import org.jeecg.config.security.utils.SecureUtil;
|
|
|
import org.jeecg.modules.adweb.seo.dto.AvesApiSearchKeywordsDTO;
|
|
|
import org.jeecg.modules.adweb.seo.entity.SeoKeywords;
|
|
|
-import org.jeecg.modules.adweb.seo.service.ISeoKeywordsService;
|
|
|
import org.jeecg.modules.adweb.seo.service.ISeoKeywordsRankService;
|
|
|
+import org.jeecg.modules.adweb.seo.service.ISeoKeywordsService;
|
|
|
+import org.jeecg.modules.system.entity.SysUser;
|
|
|
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
|
|
+import org.jeecgframework.poi.excel.entity.ExportParams;
|
|
|
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -162,25 +168,74 @@ public class SeoKeywordsController extends JeecgController<SeoKeywords, ISeoKeyw
|
|
|
* 导出excel
|
|
|
*
|
|
|
* @param request
|
|
|
- * @param seoKeywords
|
|
|
*/
|
|
|
@PreAuthorize("@jps.requiresPermissions('serp:seo_keywords:exportXls')")
|
|
|
@RequestMapping(value = "/exportXls")
|
|
|
- public ModelAndView exportXls(HttpServletRequest request, SeoKeywords seoKeywords) {
|
|
|
- return super.exportXls(request, seoKeywords, SeoKeywords.class, "关键词");
|
|
|
- }
|
|
|
+ public ModelAndView exportXls(HttpServletRequest request) throws Exception {
|
|
|
+ // Step.1 组装查询条件
|
|
|
+// QueryWrapper<SysUser> queryWrapper = QueryGenerator.initQueryWrapper(sysUser, request.getParameterMap());
|
|
|
+ //Step.2 AutoPoi 导出Excel
|
|
|
+ ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
|
|
+ //update-begin--Author:kangxiaolin Date:20180825 for:[03]用户导出,如果选择数据则只导出相关数据--------------------
|
|
|
+// String selections = request.getParameter("selections");
|
|
|
+// if(!oConvertUtils.isEmpty(selections)){
|
|
|
+// queryWrapper.in("id",selections.split(","));
|
|
|
+// }
|
|
|
+ //update-end--Author:kangxiaolin Date:20180825 for:[03]用户导出,如果选择数据则只导出相关数据----------------------
|
|
|
+// List<SysUser> pageList = sysUserService.list(queryWrapper);
|
|
|
+ AvesApiSearchKeywordsDTO avesApiSearchKeywordsDTO = new AvesApiSearchKeywordsDTO();
|
|
|
+ Result<?> res = this.queryRankInfoList(avesApiSearchKeywordsDTO, 1, 5000, request);
|
|
|
+ if (res == null || res.getResult() == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ IPage<SeoKeywords> pageList = (IPage<SeoKeywords>) res.getResult();
|
|
|
+ if (pageList.getRecords().isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ ArrayList<String> columns = null;
|
|
|
+ // 表头信息
|
|
|
+ if (sysBaseAPI.isAdmin()) {
|
|
|
+ columns = new ArrayList<>(Arrays.asList("序号", "关键词", "url", "关键词类型"));
|
|
|
+ } else {
|
|
|
+ columns = new ArrayList<>(Arrays.asList("序号", "关键词", "关键词类型"));
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 通过excel导入数据
|
|
|
- *
|
|
|
- * @param request
|
|
|
- * @param response
|
|
|
- * @return
|
|
|
- */
|
|
|
- @PreAuthorize("@jps.requiresPermissions('serp:seo_keywords:importExcel')")
|
|
|
- @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
- public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
- return super.importExcel(request, response, SeoKeywords.class);
|
|
|
+ // 将关键词信息改为可以导出的格式
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+ List<SeoKeywords> enquiryList = pageList.getRecords();
|
|
|
+
|
|
|
+ List<String> dates = pageList.getRecords().get(0).getDateList();
|
|
|
+ columns.addAll(dates);
|
|
|
+
|
|
|
+ boolean isAdmin = sysBaseAPI.isAdmin();
|
|
|
+
|
|
|
+ for (int i = 0; i < enquiryList.size(); i++) {
|
|
|
+ SeoKeywords seoKeywords = enquiryList.get(i);
|
|
|
+ Map<String, Object> map = new LinkedHashMap<>();
|
|
|
+ map.put("序号", i + 1);
|
|
|
+ map.put("关键词", seoKeywords.getKeywords());
|
|
|
+ if (isAdmin) {
|
|
|
+ map.put("url", seoKeywords.getPositionUrl());
|
|
|
+ }
|
|
|
+ if(seoKeywords.getKeywordType() == 1) {
|
|
|
+ map.put("关键词类型", "指定词");
|
|
|
+ } else if(seoKeywords.getKeywordType() == 2) {
|
|
|
+ map.put("关键词类型", "长尾词");
|
|
|
+ }
|
|
|
+ // 遍历日期
|
|
|
+ for (String date : dates) {
|
|
|
+ map.put(date,Integer.valueOf(seoKeywords.getRankInfo().get(date) == null ? "0" : seoKeywords.getRankInfo().get(date)));
|
|
|
+ }
|
|
|
+ list.add(map);
|
|
|
+ }
|
|
|
+ //导出文件名称
|
|
|
+ mv.addObject(NormalExcelConstants.FILE_NAME, "关键词排行");
|
|
|
+ mv.addObject(NormalExcelConstants.CLASS, SysUser.class);
|
|
|
+ LoginUser user = SecureUtil.currentUser();
|
|
|
+ ExportParams exportParams = new ExportParams("关键词排行数据", "导出人:"+user.getRealname(), "导出信息");
|
|
|
+ mv.addObject(NormalExcelConstants.PARAMS, exportParams);
|
|
|
+ mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
|
|
+ return mv;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -247,12 +302,12 @@ public class SeoKeywordsController extends JeecgController<SeoKeywords, ISeoKeyw
|
|
|
public void exportExcel(AvesApiSearchKeywordsDTO avesApiSearchKeywordsDTO,
|
|
|
HttpServletRequest req,
|
|
|
HttpServletResponse response) throws Exception {
|
|
|
- Result res = this.queryRankInfoList(avesApiSearchKeywordsDTO, 1, 5000, req);
|
|
|
+ Result<?> res = this.queryRankInfoList(avesApiSearchKeywordsDTO, 1, 5000, req);
|
|
|
if (res == null || res.getResult() == null) {
|
|
|
return;
|
|
|
}
|
|
|
IPage<SeoKeywords> pageList = (IPage<SeoKeywords>) res.getResult();
|
|
|
- if (pageList.getRecords().size() == 0) {
|
|
|
+ if (pageList.getRecords().isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
ArrayList<String> columns = null;
|
|
@@ -305,6 +360,7 @@ public class SeoKeywordsController extends JeecgController<SeoKeywords, ISeoKeyw
|
|
|
// 设置请求头属性
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xlsx").getBytes(), StandardCharsets.ISO_8859_1));
|
|
|
out = response.getOutputStream();
|
|
|
+ log.info("导出数据:" + list);
|
|
|
writer.write(list, true);
|
|
|
seoKeywordsRankService.setSizeColumn(sheet, list.get(0).size());
|
|
|
// 写出到文件
|