Commit 1b1f6d42 by shenjunjie

Merge branch 'release' into 'master'

Release

See merge request !237
parents 71303afd 917a3985
......@@ -152,9 +152,18 @@ public class AppSearchController extends BaseController {
@ApiOperation("搜索-全网搜-舆情导出")
@PostMapping("/exportSearchWhole")
public ResponseResult exportSearchWhole(@RequestBody SearchFilterDTO dto) {
long time = DateUtils.addDays(Tools.truncDate(new Date(), Constant.DAY_PATTERN), -89).getTime();
if (time > dto.getStartTime()) {
return ResponseResult.failure("仅能导出近3个月内信息");
// 针对商业数据库做限制
if (2 == projectService.getProjectById(UserThreadLocal.getProjectId()).getWholeSearchDataSource()) {
long time = DateUtils.addDays(Tools.truncDate(new Date(), Constant.DAY_PATTERN), -89).getTime();
if (time > dto.getStartTime()) {
// 仅对查商业数据库时限制时间,查舆情库时本质上无时间限制
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);
EasyExcelUtil.download("全网搜舆情列表数据", "sheet1", ExportSearchWholeDTO.class, exportList, response);
......
......@@ -5,6 +5,7 @@ import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import java.util.Date;
......@@ -43,9 +44,10 @@ public class ExportSearchWholeDTO {
dto.setTime(new Date((Long) jsonObject.get("time")));
dto.setPlatform(jsonObject.getString("platform"));
dto.setChannel(jsonObject.getString("channel"));
dto.setTitle(jsonObject.getString("title"));
dto.setContent(jsonObject.getString("content"));
dto.setUrl(jsonObject.getString("url"));
// 截取为excel单元格允许的最大长度
dto.setTitle(StringUtils.substring(jsonObject.getString("title"), 0, 32767));
dto.setContent(StringUtils.substring(jsonObject.getString("content"), 0, 32767));
dto.setUrl(StringUtils.substring(jsonObject.getString("url"), 0, 32767));
return dto;
}
}
......@@ -131,6 +131,9 @@ public class MarkDataServiceImpl implements MarkDataService {
@Resource(name = "channelDao")
ChannelDao channelDao;
@Resource(name = "userServiceImpl")
private UserService userService;
@Resource(name = "redisUtil")
RedisUtil redisUtil;
......@@ -1337,8 +1340,24 @@ public class MarkDataServiceImpl implements MarkDataService {
@Override
public List<ExportSearchWholeDTO> exportSearchWhole(SearchFilterDTO dto) {
JSONObject jsonObject = searchWholeNetwork(dto);
JSONArray jsonArray = jsonObject.getJSONArray("list");
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);
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());
}
......
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