|
@@ -18,6 +18,7 @@ import org.springblade.useranalysis.dto.param.ExcelExportParam;
|
|
import org.springblade.useranalysis.entity.TagColumn;
|
|
import org.springblade.useranalysis.entity.TagColumn;
|
|
import org.springblade.useranalysis.entity.UserGroupEntity;
|
|
import org.springblade.useranalysis.entity.UserGroupEntity;
|
|
import org.springblade.useranalysis.entity.UserProfileExcelLog;
|
|
import org.springblade.useranalysis.entity.UserProfileExcelLog;
|
|
|
|
+import org.springblade.useranalysis.entity.clickhouse.ZUserTagEntity;
|
|
import org.springblade.useranalysis.service.UserProfileService;
|
|
import org.springblade.useranalysis.service.UserProfileService;
|
|
import org.springblade.useranalysis.service.UserTagsService;
|
|
import org.springblade.useranalysis.service.UserTagsService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -28,6 +29,7 @@ import com.alibaba.excel.ExcelWriter;
|
|
import com.alibaba.excel.converters.longconverter.LongStringConverter;
|
|
import com.alibaba.excel.converters.longconverter.LongStringConverter;
|
|
import com.alibaba.excel.util.FileUtils;
|
|
import com.alibaba.excel.util.FileUtils;
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.github.xiaoymin.knife4j.core.util.StrUtil;
|
|
import com.github.xiaoymin.knife4j.core.util.StrUtil;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -50,6 +52,9 @@ public class ExcelService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private UserProfileService userProfileService;
|
|
private UserProfileService userProfileService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserGroupRuleService userGroupRuleService;
|
|
|
|
|
|
final ExecutorService threadPool = new ThreadPoolExecutor(1, 2, 5, TimeUnit.MINUTES,
|
|
final ExecutorService threadPool = new ThreadPoolExecutor(1, 2, 5, TimeUnit.MINUTES,
|
|
// 有界队列5000,超过队列长度,无异常抛弃
|
|
// 有界队列5000,超过队列长度,无异常抛弃
|
|
@@ -68,8 +73,31 @@ public class ExcelService {
|
|
log.info(excelLog.getId() + " - exporting......");
|
|
log.info(excelLog.getId() + " - exporting......");
|
|
long start = System.currentTimeMillis();
|
|
long start = System.currentTimeMillis();
|
|
try {
|
|
try {
|
|
|
|
+ String groupId = params.getGroupId();
|
|
|
|
+ // 使用前端传递的日期范围
|
|
|
|
+// String monthStart = params.getMonthStart();
|
|
|
|
+// String monthEnd = params.getMonthEnd();
|
|
|
|
+
|
|
|
|
+ // 使用圈定人群的日期范围
|
|
|
|
+// String monthStart = "";
|
|
|
|
+// String monthEnd = "";
|
|
|
|
+// JSONObject rule = JSON.parseObject(userGroup.getRules());
|
|
|
|
+// if (rule != null) {
|
|
|
|
+// if (rule.containsKey("daterange")) {
|
|
|
|
+// JSONArray daterange = rule.getJSONArray("daterange");
|
|
|
|
+// if (daterange != null && daterange.size() == 2) {
|
|
|
|
+// monthStart = daterange.getString(0);
|
|
|
|
+// monthEnd = daterange.getString(1);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+ QueryWrapper<ZUserTagEntity> whereWrapper = userGroupRuleService.parse(userGroup);
|
|
|
|
+ whereWrapper.eq("ur.user_group_id ", groupId);
|
|
|
|
+ //whereWrapper解析后已经包含日期范围,所以不需要再添加时间,只需要追加人群id即可
|
|
|
|
+// whereWrapper.ge("tag.THEMONTH_V", monthStart);
|
|
|
|
+// whereWrapper.le("tag.THEMONTH_V", monthEnd);
|
|
ConcurrentHashMap<String, String> mobileMap = new ConcurrentHashMap<>();
|
|
ConcurrentHashMap<String, String> mobileMap = new ConcurrentHashMap<>();
|
|
- boolean isSuccess = handle(mobileMap, params, excelLog, userGroup);
|
|
|
|
|
|
+ boolean isSuccess = handle(mobileMap, params, excelLog, userGroup, whereWrapper);
|
|
if (isSuccess) {
|
|
if (isSuccess) {
|
|
excelLog.setCount(params.getCount());
|
|
excelLog.setCount(params.getCount());
|
|
excelLog.setStatus(UserProfileExcelLogService.STATUS_SUCCESS);
|
|
excelLog.setStatus(UserProfileExcelLogService.STATUS_SUCCESS);
|
|
@@ -101,7 +129,7 @@ public class ExcelService {
|
|
}
|
|
}
|
|
|
|
|
|
private boolean handle(ConcurrentHashMap<String, String> mobileMap, ExcelExportParam params,
|
|
private boolean handle(ConcurrentHashMap<String, String> mobileMap, ExcelExportParam params,
|
|
- UserProfileExcelLog excelLog, UserGroupEntity userGroup) {
|
|
|
|
|
|
+ UserProfileExcelLog excelLog, UserGroupEntity userGroup, QueryWrapper<ZUserTagEntity> whereWrapper) {
|
|
boolean isSuccess = true;
|
|
boolean isSuccess = true;
|
|
List<String> codeList = params.getTagList();
|
|
List<String> codeList = params.getTagList();
|
|
boolean desens = params.isDesens();
|
|
boolean desens = params.isDesens();
|
|
@@ -124,31 +152,13 @@ public class ExcelService {
|
|
.registerConverter(new LongStringConverter())
|
|
.registerConverter(new LongStringConverter())
|
|
.head(buidlHeader(columnList))
|
|
.head(buidlHeader(columnList))
|
|
.build();
|
|
.build();
|
|
- String groupId = params.getGroupId();
|
|
|
|
- // 使用前端传递的日期范围
|
|
|
|
- String monthStart = params.getMonthStart();
|
|
|
|
- String monthEnd = params.getMonthEnd();
|
|
|
|
-
|
|
|
|
- // 使用圈定人群的日期范围
|
|
|
|
- // String monthStart = "";
|
|
|
|
- // String monthEnd = "";
|
|
|
|
- // JSONObject rule = JSON.parseObject(userGroup.getRules());
|
|
|
|
- // if (rule != null) {
|
|
|
|
- // if (rule.containsKey("daterange")) {
|
|
|
|
- // JSONArray daterange = rule.getJSONArray("daterange");
|
|
|
|
- // if (daterange != null && daterange.size() == 2) {
|
|
|
|
- // monthStart = daterange.getString(0);
|
|
|
|
- // monthEnd = daterange.getString(1);
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
// 需要导出的数量
|
|
// 需要导出的数量
|
|
int count = params.getCount();
|
|
int count = params.getCount();
|
|
log.info("export count need is :" + count);
|
|
log.info("export count need is :" + count);
|
|
-
|
|
|
|
|
|
+
|
|
// 已经导出的数量
|
|
// 已经导出的数量
|
|
int exportedCountTotal = 0;
|
|
int exportedCountTotal = 0;
|
|
-
|
|
|
|
|
|
+
|
|
// 下次查询偏移量
|
|
// 下次查询偏移量
|
|
int offset = 0;
|
|
int offset = 0;
|
|
|
|
|
|
@@ -158,7 +168,7 @@ public class ExcelService {
|
|
List<Map<String, Object>> tagList = null;
|
|
List<Map<String, Object>> tagList = null;
|
|
try {
|
|
try {
|
|
log.info("export limit sql is :" + sqlLimit);
|
|
log.info("export limit sql is :" + sqlLimit);
|
|
- tagList = userTagsService.exportUserGroup(fields.toString(), groupId, monthStart, monthEnd, sqlLimit);
|
|
|
|
|
|
+ tagList = userTagsService.exportUserGroup(fields.toString(), whereWrapper, sqlLimit);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("ExcelService handle fail, the error is " + e.getMessage());
|
|
log.error("ExcelService handle fail, the error is " + e.getMessage());
|
|
isSuccess = false;
|
|
isSuccess = false;
|
|
@@ -192,7 +202,6 @@ public class ExcelService {
|
|
return isSuccess;
|
|
return isSuccess;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 结果导出到excel文件中
|
|
* 结果导出到excel文件中
|
|
*
|
|
*
|
|
@@ -263,7 +272,7 @@ public class ExcelService {
|
|
excelWriter.write(list, EasyExcel.writerSheet(groupName).build());
|
|
excelWriter.write(list, EasyExcel.writerSheet(groupName).build());
|
|
return count;
|
|
return count;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 动态生成表头
|
|
* 动态生成表头
|
|
*/
|
|
*/
|