Commit 917a3985 by shenjunjie

Merge branch 'feature' into 'release'

Feature

See merge request !236
parents 57444a46 a0809518
...@@ -152,10 +152,19 @@ public class AppSearchController extends BaseController { ...@@ -152,10 +152,19 @@ public class AppSearchController extends BaseController {
@ApiOperation("搜索-全网搜-舆情导出") @ApiOperation("搜索-全网搜-舆情导出")
@PostMapping("/exportSearchWhole") @PostMapping("/exportSearchWhole")
public ResponseResult exportSearchWhole(@RequestBody SearchFilterDTO dto) { public ResponseResult exportSearchWhole(@RequestBody SearchFilterDTO dto) {
// 针对商业数据库做限制
if (2 == projectService.getProjectById(UserThreadLocal.getProjectId()).getWholeSearchDataSource()) {
long time = DateUtils.addDays(Tools.truncDate(new Date(), Constant.DAY_PATTERN), -89).getTime(); long time = DateUtils.addDays(Tools.truncDate(new Date(), Constant.DAY_PATTERN), -89).getTime();
if (time > dto.getStartTime()) { if (time > dto.getStartTime()) {
// 仅对查商业数据库时限制时间,查舆情库时本质上无时间限制
return ResponseResult.failure("仅能导出近3个月内信息"); return ResponseResult.failure("仅能导出近3个月内信息");
} }
Period periodDay = new Period(dto.getStartTime(), dto.getEndTime(), PeriodType.days());
if (periodDay.getDays() > 30) {
// 仅对查商业数据库时限制时间,查舆情库时本质上无时间限制
return ResponseResult.failure("时间跨度不能超过30天");
}
}
List<ExportSearchWholeDTO> exportList = markDataService.exportSearchWhole(dto); List<ExportSearchWholeDTO> exportList = markDataService.exportSearchWhole(dto);
EasyExcelUtil.download("全网搜舆情列表数据", "sheet1", ExportSearchWholeDTO.class, exportList, response); EasyExcelUtil.download("全网搜舆情列表数据", "sheet1", ExportSearchWholeDTO.class, exportList, response);
return ResponseResult.success(); return ResponseResult.success();
......
...@@ -5,6 +5,7 @@ import com.alibaba.excel.annotation.write.style.ColumnWidth; ...@@ -5,6 +5,7 @@ import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.Data; import lombok.Data;
import lombok.ToString; import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import java.util.Date; import java.util.Date;
...@@ -43,9 +44,10 @@ public class ExportSearchWholeDTO { ...@@ -43,9 +44,10 @@ public class ExportSearchWholeDTO {
dto.setTime(new Date((Long) jsonObject.get("time"))); dto.setTime(new Date((Long) jsonObject.get("time")));
dto.setPlatform(jsonObject.getString("platform")); dto.setPlatform(jsonObject.getString("platform"));
dto.setChannel(jsonObject.getString("channel")); dto.setChannel(jsonObject.getString("channel"));
dto.setTitle(jsonObject.getString("title")); // 截取为excel单元格允许的最大长度
dto.setContent(jsonObject.getString("content")); dto.setTitle(StringUtils.substring(jsonObject.getString("title"), 0, 32767));
dto.setUrl(jsonObject.getString("url")); dto.setContent(StringUtils.substring(jsonObject.getString("content"), 0, 32767));
dto.setUrl(StringUtils.substring(jsonObject.getString("url"), 0, 32767));
return dto; return dto;
} }
} }
...@@ -131,6 +131,9 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -131,6 +131,9 @@ public class MarkDataServiceImpl implements MarkDataService {
@Resource(name = "channelDao") @Resource(name = "channelDao")
ChannelDao channelDao; ChannelDao channelDao;
@Resource(name = "userServiceImpl")
private UserService userService;
@Resource(name = "redisUtil") @Resource(name = "redisUtil")
RedisUtil redisUtil; RedisUtil redisUtil;
...@@ -1337,8 +1340,24 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -1337,8 +1340,24 @@ public class MarkDataServiceImpl implements MarkDataService {
@Override @Override
public List<ExportSearchWholeDTO> exportSearchWhole(SearchFilterDTO dto) { public List<ExportSearchWholeDTO> exportSearchWhole(SearchFilterDTO dto) {
Integer exportAmount = userService.queryUserInfo(UserThreadLocal.getUserId(), UserThreadLocal.getProjectId()).getExportAmount();
exportAmount = Objects.isNull(exportAmount) ? 10000 : exportAmount;
JSONArray jsonArray = new JSONArray();
dto.setPageSize(50);
dto.setPage(1);
while (true){
if (dto.getPage() * dto.getPageSize() > exportAmount){
break;
}
// 获取当页数据
JSONObject jsonObject = searchWholeNetwork(dto); JSONObject jsonObject = searchWholeNetwork(dto);
JSONArray jsonArray = jsonObject.getJSONArray("list"); JSONArray array = jsonObject.getJSONArray("list");
if (Objects.isNull(array) || 0 == array.size()){
break;
}
jsonArray.addAll(array);
dto.setPage(dto.getPage() + 1);
}
return jsonArray.stream().map(json -> ExportSearchWholeDTO.creatExportSearchWholeDTO((JSONObject) json)).collect(Collectors.toList()); return jsonArray.stream().map(json -> ExportSearchWholeDTO.creatExportSearchWholeDTO((JSONObject) json)).collect(Collectors.toList());
} }
......
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